package top.yonyong.java8.BLambda表达式.一示例;

/**
 * @author yonyong
 **/
public class Main {
    public static void main(String[] args) {
        System.out.println("使用lambda表达式前提：接口必须是函数式接口（除了默认方法和静态方法之外，接口里只能有一个方法）");

        //java8 之前，匿名内部类
        System.out.println("java8 之前，匿名内部类:");
        TestService testService = new TestService() {
            @Override
            public int sub(int a, int b) {
                return a - b;
            }
        };
        System.out.println(testService.sub(10, 5));

        //java8之后
        System.out.println("lambda表达式--实现方式1:");
        TestService testService1 = (a, b) -> {
            return a - b;
        };
        System.out.println(testService1.sub(10, 5));

        System.out.println("lambda表达式--实现方式2，省略花括号:");
        TestService testService2 = (a, b) -> a - b;
        System.out.println(testService2.sub(10, 5));

        System.out.println("lambda表达式--测试无参调用");
        LambdaTest lambdaTest = () -> System.out.println("11111");
        lambdaTest.print();

        System.out.println("lambda表达式--只有一个参数方法");
        LambdaTest2 lambdaTest2 = System.out::println;
        //或者
        //LambdaTest2 lambdaTest2 = s -> System.out.println(s);
        lambdaTest2.print("holly shit");
    }
}
